<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<?php 
    $conn=null;//定义全局变量
	$sql = null;

    function executeSql($sql){
		$flag = false;
		if($sql == ""){
			echo "Error! Sql content is empty!";
			echo "<br>";
		}else{

			$servername = 'localhost';
			$port = '9306';
			$dbname = 'group13';
			$username = 'example_user';
			$password = 'example_password';

			example_password

			// $servername = '106.15.226.153';
			// $port = '3306';
			// $dbname = 'z_db';
			// $username = 'root';
			// $password = 'Nokia123456!';

			// 创建连接
			$conn = new mysqli($servername,  $username, $password, $dbname, $port);
			// 检测连接
			if ($conn->connect_error) {
				die("Fail to connect!: " . $conn->connect_error);
			}
			//执行sql语句
			// if ($conn->query($sql) === TRUE) {
			// 	$flag = TRUE;
			// } else {
			// 	echo "Error: " . $sql . "<br>" . $conn->error;
			// }
			// $conn->close();
			// return $flag;

			$result = $conn->query($sql);
			if ($result->num_rows > 0) {
				while ($row = $result->fetch_assoc()) {
					// 处理每一行的数据
					echo "Product ID: {$row['id']}, Name: {$row['file_path']}, Price: {$row['file_type']}<br>";
				}
			} else {
				echo "No products found.";
			}
		}
	}
    
    $Id = ''; // 在这行之前定义 $Id 变量，并赋一个默认值

    if(isset($_POST["Id"])) {  
        $Id = $_POST["Id"]; 
        $Name = $_POST["Name"]; 
        $Price = $_POST["Price"]; 
        $Filling = $_POST["Filling"]; 
        $CoChoice = $_POST["Choice"]; 
        $Descr = $_POST["descr"];
    }

    if($Id ==""||$Name ==""||$Price ==""||$Filling ==""||$CoChoice ==""||$Descr ==""){
		echo "You can not provide empty values!";
	}else{
		// $sql = "INSERT INTO product_info(Id,Name,Price,Internal Filling,Color Choice,Brief Descriptions) VALUES 
		// ('".$Id."','".$Name."','".$Price."','".$Filling."','".$CoChoice."','".$Descr."');";
		$sql = 'select * from media_info limit 100';
    }

	echo $sql;
	executeSql($sql);


?>    
</body>
</html>
